import coin.strategy.mm.simple_sim.profile.agg_fast_base as agg_fast_base

from coin.exchange.bitmex.kr_rest.futures_product import BitmexFuturesProduct
from coin.support.feed_tool.feed_stats.logic.feed_health_checker import (
    filter_common_good_trading_dates)

PASS_ALPHA_FILEPATH = 'profile/pass_bitmex_product/linear_alpha.json'


def get_products(from_ts):
  return agg_fast_base.get_products(from_ts, PASS_ALPHA_FILEPATH)


def get_machines():
  return ['feed-01.eu-west-1.aws']


def get_strategy(from_ts, to_ts):
  executor_param = {
      'maker_fee': -2.5 / 10000.,
      'taker_fee': 7.5 / 10000.,
      'execution_delay': 1 * (10**9),
      'trade_qty_func': (lambda trade: 100 * trade.qty / trade.price),
      'post_only': True,
  }
  return agg_fast_base.get_strategy(from_ts,
                                    to_ts,
                                    BitmexFuturesProduct.FromStr('BTC-USD.PERPETUAL'),
                                    PASS_ALPHA_FILEPATH,
                                    executor_param,
                                    agg=False,
                                    null=True)


def get_date_ranges():
  dates = agg_fast_base.get_date_ranges()
  if not dates:
    return []
  from_ts = dates[0]
  machine = get_machines()[0]
  products = get_products(from_ts)
  good_dates = filter_common_good_trading_dates(dates, machine, products)
  return good_dates


def get_time_ranges():
  if agg_fast_base.P_FLAGS.filter_dates:
    return agg_fast_base.get_time_ranges(get_date_ranges())
  else:
    return agg_fast_base.get_time_ranges()


get_strategy_result = agg_fast_base.get_strategy_result
aggregate_result = agg_fast_base.aggregate_result
